home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / xml4j.jar / com / ibm / xml / parser / TXAttribute.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-08-30  |  5.8 KB  |  281 lines

  1. package com.ibm.xml.parser;
  2.  
  3. import java.io.StringWriter;
  4. import org.w3c.dom.Attr;
  5. import org.w3c.dom.DOMException;
  6. import org.w3c.dom.EntityReference;
  7. import org.w3c.dom.Node;
  8. import org.w3c.dom.Text;
  9.  
  10. public class TXAttribute extends Parent implements Attr, Namespace {
  11.    static final long serialVersionUID = 710791704404680525L;
  12.    String name;
  13.    String value;
  14.    int type = 0;
  15.    String[] typedValue;
  16.    boolean specified = false;
  17.  
  18.    public TXAttribute(String var1, String var2) {
  19.       this.name = var1;
  20.       this.value = var2;
  21.       this.specified = true;
  22.    }
  23.  
  24.    public Object clone() {
  25.       return this.cloneNode(true);
  26.    }
  27.  
  28.    public synchronized Node cloneNode(boolean var1) {
  29.       ((Child)this).checkFactory();
  30.       TXAttribute var2 = (TXAttribute)super.factory.createAttribute(this.name);
  31.       ((Child)var2).setFactory(((Child)this).getFactory());
  32.       if (var1) {
  33.          var2.children.ensureCapacity(super.children.getLength());
  34.  
  35.          for(int var3 = 0; var3 < super.children.getLength(); ++var3) {
  36.             ((Parent)var2).insertBefore(super.children.item(var3).cloneNode(true), (Node)null);
  37.          }
  38.       }
  39.  
  40.       var2.setType(this.getType(), this.getTypedValue());
  41.       var2.setSpecified(this.getSpecified());
  42.       return var2;
  43.    }
  44.  
  45.    public synchronized boolean equals(Node var1, boolean var2) {
  46.       if (var1 == null) {
  47.          return false;
  48.       } else if (!(var1 instanceof TXAttribute)) {
  49.          return false;
  50.       } else {
  51.          TXAttribute var3 = (TXAttribute)var1;
  52.          if (!var3.getName().equals(this.getName())) {
  53.             return false;
  54.          } else if (!var3.getValue().equals(this.getValue())) {
  55.             return false;
  56.          } else {
  57.             return !var2 || var3.children.equals(super.children, var2);
  58.          }
  59.       }
  60.    }
  61.  
  62.    public short getNodeType() {
  63.       return 2;
  64.    }
  65.  
  66.    public String getNodeName() {
  67.       return this.name;
  68.    }
  69.  
  70.    public String getName() {
  71.       return this.name;
  72.    }
  73.  
  74.    public String getValue() {
  75.       if (this.value != null) {
  76.          return this.value;
  77.       } else {
  78.          this.value = ((Parent)this).getText();
  79.          return this.value;
  80.       }
  81.    }
  82.  
  83.    public String getNodeValue() {
  84.       return this.getValue();
  85.    }
  86.  
  87.    public String toString() {
  88.       return this.getValue();
  89.    }
  90.  
  91.    public void setValue(String var1) {
  92.       this.setNodeValue(var1);
  93.    }
  94.  
  95.    public void setNodeValue(String var1) {
  96.       this.value = var1;
  97.       if (var1 != null) {
  98.          TXNodeList var2 = super.children;
  99.          synchronized(var2){}
  100.  
  101.          try {
  102.             while(((Parent)this).getFirstChild() != null) {
  103.                this.removeChild(((Parent)this).getFirstChild());
  104.             }
  105.  
  106.             ((Child)this).checkFactory();
  107.             ((Parent)this).appendChild(super.factory.createAttributeValue(var1));
  108.          } catch (Throwable var4) {
  109.             throw var4;
  110.          }
  111.       }
  112.  
  113.       ((Child)this).clearDigest();
  114.    }
  115.  
  116.    protected void realInsert(Node var1, int var2) throws LibraryException {
  117.       if (!(var1 instanceof Text) && !(var1 instanceof EntityReference)) {
  118.          throw new TXDOMException((short)3, "com.ibm.xml.parser.TXAttribute#realInsert(): Nodes except Text/EntityReference are not allowed as attribute children.");
  119.       } else {
  120.          super.realInsert(var1, var2);
  121.          this.value = null;
  122.       }
  123.    }
  124.  
  125.    public Node replaceChild(Node var1, Node var2) throws DOMException {
  126.       if (!(var1 instanceof Text) && !(var1 instanceof EntityReference)) {
  127.          throw new TXDOMException((short)3, "com.ibm.xml.parser.TXAttribute#realInsert(): Nodes except Text/EntityReference are not allowed as attribute children.");
  128.       } else {
  129.          this.value = null;
  130.          return super.replaceChild(var1, var2);
  131.       }
  132.    }
  133.  
  134.    public Node removeChild(Node var1) throws DOMException {
  135.       this.value = null;
  136.       return super.removeChild(var1);
  137.    }
  138.  
  139.    public boolean getSpecified() {
  140.       return this.specified;
  141.    }
  142.  
  143.    public void setSpecified(boolean var1) {
  144.       this.specified = var1;
  145.    }
  146.  
  147.    public String getNSLocalName() {
  148.       return TXElement.getLocalNameForQName(this.getNodeName());
  149.    }
  150.  
  151.    public String getNSName() {
  152.       Node var1 = super.parent;
  153.       if (var1 == null) {
  154.          new LibraryException("This attribute isn't assigned to any Element.");
  155.       }
  156.  
  157.       return this.getNodeName().indexOf(58) < 0 ? null : ((TXElement)var1).getNamespaceForQName(this.getNodeName());
  158.    }
  159.  
  160.    /** @deprecated */
  161.    public String getUniversalName() {
  162.       return this.getNSName() == null ? this.getNSLocalName() : this.getNSName() + ":" + this.getNSLocalName();
  163.    }
  164.  
  165.    public String createExpandedName() {
  166.       if ("xmlns".equals(this.getNodeName())) {
  167.          return "xmlns";
  168.       } else {
  169.          String var1 = this.getNSName();
  170.          return var1 != null && var1.length() != 0 ? var1 + ((Child)this).getFactory().expandedNameSeparator + this.getNSLocalName() : ((TXElement)super.parent).createExpandedName() + ((Child)this).getFactory().expandedNameSeparator + this.getNodeName();
  171.       }
  172.    }
  173.  
  174.    public int getType() {
  175.       return this.type;
  176.    }
  177.  
  178.    public String[] getTypedValue() {
  179.       return this.typedValue;
  180.    }
  181.  
  182.    public void setType(int var1, String[] var2) {
  183.       this.type = var1;
  184.       this.typedValue = var2;
  185.       this.value = normalize(var1, this.getValue());
  186.    }
  187.  
  188.    public String toXMLString(String var1) {
  189.       String var2 = null;
  190.  
  191.       try {
  192.          StringWriter var3 = new StringWriter();
  193.          ToXMLStringVisitor var4 = new ToXMLStringVisitor(var3, var1);
  194.          (new NonRecursivePreorderTreeTraversal(var4)).traverse(this);
  195.          var2 = var3.toString();
  196.       } catch (Exception var5) {
  197.       }
  198.  
  199.       return var2;
  200.    }
  201.  
  202.    public String toXMLString() {
  203.       return this.toXMLString((String)null);
  204.    }
  205.  
  206.    public boolean equals(Object var1) {
  207.       if (var1 == null) {
  208.          return false;
  209.       } else if (var1 instanceof Attr) {
  210.          return this.getName().equals(((Attr)var1).getName());
  211.       } else {
  212.          return var1 instanceof String ? this.getName().equals((String)var1) : false;
  213.       }
  214.    }
  215.  
  216.    public int hashCode() {
  217.       return this.getName().hashCode();
  218.    }
  219.  
  220.    public void acceptPre(Visitor var1) throws Exception {
  221.       var1.visitAttributePre(this);
  222.    }
  223.  
  224.    public void acceptPost(Visitor var1) throws Exception {
  225.       var1.visitAttributePost(this);
  226.    }
  227.  
  228.    public Node getOwnerElement() {
  229.       return super.parent;
  230.    }
  231.  
  232.    public Node getParentNode() {
  233.       return null;
  234.    }
  235.  
  236.    public Node getPreviousSibling() {
  237.       return null;
  238.    }
  239.  
  240.    public Node getNextSibling() {
  241.       return null;
  242.    }
  243.  
  244.    static String normalize(int var0, String var1) {
  245.       if (var0 != 0 && var0 != 1) {
  246.          var1 = var1.trim();
  247.          StringBuffer var2 = new StringBuffer(var1.length());
  248.          boolean var3 = false;
  249.  
  250.          for(int var4 = 0; var4 < var1.length(); ++var4) {
  251.             char var5 = var1.charAt(var4);
  252.             if (var5 == ' ') {
  253.                if (!var3) {
  254.                   var2.append(var5);
  255.                }
  256.  
  257.                var3 = true;
  258.             } else {
  259.                var3 = false;
  260.                var2.append(var5);
  261.             }
  262.          }
  263.  
  264.          return var2.toString();
  265.       } else {
  266.          return var1;
  267.       }
  268.    }
  269.  
  270.    protected void checkChildType(Node var1) throws DOMException {
  271.       switch (var1.getNodeType()) {
  272.          case 3:
  273.          case 5:
  274.          case 23:
  275.             return;
  276.          default:
  277.             throw new TXDOMException((short)3, "Specified node type (" + var1.getNodeType() + ") can't be a child of Attribute.");
  278.       }
  279.    }
  280. }
  281.